﻿#include "base_math_tools.h"
#include <QVector>
BaseMathTools::BaseMathTools(QObject *parent) : QObject(parent)
{

}

QString BaseMathTools::getRandomOption(int option)
{
    QVector<QString> vec;
    if(option & ADD_OPTION){
        vec.push_back(STR_ADD_OPTION);
    }
    if(option & DESC_OPTION){
        vec.push_back(STR_DESC_OPTION);
    }
    if(option & MULT_OPTION){
        vec.push_back(STR_MULT_OPTION);
    }
    if(option & DIV_OPTION){
        vec.push_back(STR_DIV_OPTION);
    }
    int r = generateRandomNumber(0,vec.size() -1);
    return vec.at(r);
}

int BaseMathTools::generateRandomNumber(int min, int max)
{
    if(min == max ){
        return min;
    }
    if(min == max && min ==0){
           return 0;
    }
    return (rand() % (max - min+1)) + min;
}

int BaseMathTools::doCount(int num1, int num2, QString op)
{
    if(STR_ADD_OPTION  == op){
       return num1+num2;
    }else if(STR_DESC_OPTION == op){
        return num1-num2;
    }else if(STR_MULT_OPTION == op){
        return num1*num2;
    }else if(STR_DIV_OPTION == op){
        return int(num1/num2);
    }
    return 0;
}
